<?php

/**
 * @copyright 2011
 * @version $Id$
 * @access public
 * @author Oriotiori

 */

class Admin_Model_Facade_Categories{
	
	/**
	 * Obtiene las categorias
	 * @param array $to: Array de datos a guardar.
	 * @return array $data
	 */
	public function getCategories($id)
	{
		$TBD_Resource = new Admin_Model_Categories();
		try{
			$data = $TBD_Resource->getCategories($id);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}
	
	
	/**
	 * Obtiene las categorias
	 * @param array $to: Array de datos a guardar.
	 * @return array $data
	 */
	public function addCategory($to)
	{
		$TBD_Resource = new Admin_Model_Categories();
		try{
			$data = $TBD_Resource->addCategory($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

	
	
	/**
	* actualiza las categorias
	* @param array $to: Array de datos a guardar.
	* @return array $data
	*/
	public function updateCategory($to)
	{
		$TBD_Resource = new Admin_Model_Categories();
		try{
			$data = $TBD_Resource->updateCategory($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}
	
	
		
	
	/**
	* @param array $to: Array de datos a guardar.
	* @return array $data
	*/
	public function AddImageDB($to)
	{
		$TBD_Resource = new Admin_Model_Categories();
		try{
			$data = $TBD_Resource->AddImageDB($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}
	
	
		
	/**
	* Obtiene las categorias by id
	* @param array $to: Array de datos.
	* @return array $data
	*/
	public function readCategoryById($id=0)
	{
		$TBD_Resource = new Admin_Model_Categories();
		try{
			$data = $TBD_Resource->readCategoryById($id);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}
	
	
	
	/**
	* Obtiene arbol de categoria
	* @param int $id: id of cat
	* @return array $data
	*/
	public function getTreeCatById($id=0)
	{
		$TBD_Resource = new Admin_Model_Categories();
		try{
			$data = $TBD_Resource->getTreeCatById($id);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}
	
	
	/**
	* @param int $id
	* @return array $data
	*/
	public function deleteCategoryById($id=0)
	{
		$TBD_Resource = new Admin_Model_Categories();
		try{
			$data = $TBD_Resource->deleteCategoryById($id);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}
	
	
		
	
	
/**
 * @param array $resource: Array de datos
 * @return boolean $data
 */
	public function CreateThumb($to)
        {
            $TBD_Resource = new Admin_Model_Categories();
            $facadeConfigs= new Admin_Model_Facade_Configs();
            $configs=$facadeConfigs->getConfigs();
            try{
            	$to['Width']=$configs['Category_Thumb_Width'];
            	$to['Height']=$configs['Category_Thumb_Height'];
                $to['Path']='Real';
                $to['Directory']='category';
                $to['NewPath']='Thumb';
                $to['mode']='Thumb';

                $data = $TBD_Resource->CreateThumb($to);
                return $data;
            }catch(Exception $e)
            {
                $error=array($e->getFile(), 'Exception: '.$e->getMessage());
                $ExceptionHandler= new Default_Model_ExceptionHandler();
                $ExceptionHandler->saveErrors($error);
            }
            return false;
	}



}
